clear

*******************************
*Table 6: Timing of elections
*******************************
use "$data\final.dta"

* redefine election year variable based on the date of the election
gen month_elect2=month_elect
replace month_elect2=l.month_elect2 if month_elect2==.

gen electyr2=electyr
replace electyr2=0 if electyr==1 & month_elect2<3

gen direct_elect2=direct_elect
replace direct_elect2=0 if direct_elect==1 & month_elect2<3 & year==first

gen bmwahl2=bmwahl
replace bmwahl2=0 if bmwahl==1 & month_elect2<3
****
gen electyr4=electyr
replace electyr4=0 if electyr==1 & month_elect2<5

gen direct_elect4=direct_elect
replace direct_elect4=0 if direct_elect==1 & month_elect2<5 & year==first

gen bmwahl4=bmwahl
replace bmwahl4=0 if bmwahl==1 & month_elect2<5
****
gen electyr6=electyr
replace electyr6=0 if electyr==1 & month_elect2<7

gen direct_elect6=direct_elect
replace direct_elect6=0 if direct_elect==1 & month_elect2<7 & year==first

gen bmwahl6=bmwahl
replace bmwahl6=0 if bmwahl==1 & month_elect2<7

* redefine pre_any_system such that it is only 1 in the election year
replace pre_any_system=0 if pre_any_system==1 & electyr==1

xtivreg2 log_Invzuweis_pc direct_elect2 bmwahl2 electyr2 time* trend_* bis14jahre_sh ueber65_sh log_Schluess_pc logpop businesstax proptax, fe r cluster(code)
est store inv1
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "YES", replace

xtivreg2 log_Invzuweis_pc direct_elect4 bmwahl4 electyr4 time* trend_* bis14jahre_sh ueber65_sh log_Schluess_pc logpop businesstax proptax, fe r cluster(code)
est store inv2
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "YES", replace

xtivreg2 log_Invzuweis_pc direct_elect6 bmwahl6 electyr6 time* trend_* bis14jahre_sh ueber65_sh log_Schluess_pc logpop businesstax proptax, fe r cluster(code)
est store inv3
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "YES", replace

preserve
xtivreg2 log_Invzuweis_pc direct_elect pre_bmwahl bmwahl pre_any_system electyr time* trend_* bis14jahre_sh ueber65_sh log_Schluess_pc logpop businesstax proptax, fe r cluster(code)
est store inv4
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "YES", replace
restore

estout inv1 inv2 inv3 inv4 using "$data\table6.tex", ///
rename(appointment councilwahl direct_elect2 direct_elect  bmwahl2 bmwahl electyr2 electyr direct_elect4 direct_elect  bmwahl4 bmwahl electyr4 electyr direct_elect6 direct_elect  bmwahl6 bmwahl electyr6 electyr) ///
style(tex) keep(direct_elect* bmwahl* electyr* pre_bmwahl pre_any_system) mlabels("(I)" "(II)" "(III)" "(IV)") order(pre_bmwahl bmwahl* direct_elect*  pre_any_system electyr*  ) replace title("Robustness check 1: Electoral cycles in investment transfers from the state-tier by electoral rules for mayors, timing of elections") ///
 prehead(\begin{table}[htbp] \scriptsize \hspace{\fill} \resizebox{1\textwidth}{!}{\begin{threeparttable}\caption{{\sc @title \label{tab:timing1}}}\centering\medskip ///
 \begin{tabularx}{1.1\textwidth}{P*{@M}{C}} \toprule \\ "&\multicolumn{3}{l}{Only late elections}& \multicolumn{1}{l}{Pre-election year}\\ \cmidrule(r){2-4} \cmidrule(r){5-5}\\&\multicolumn{1}{l}{March-December}& \multicolumn{1}{l}{May-December} & \multicolumn{1}{l}{July-December} & \multicolumn{1}{l}{ }\\   \cmidrule(r){2-2} \cmidrule(r){3-3} \cmidrule(r){4-4} \cmidrule(r){5-5}"\\) ///
  posthead("") prefoot("\midrule") ///
 varlabels(electyr2 "Election/appointment year" electyr "Election/appointment year" bmwahl "Elected mayor*Election/appointment year" bmwahl2 "Elected mayor*Election/appointment year" direct_elect "Elected mayor" direct_elect2 "Elected mayor" log_Schluess_pc "Log of rule-based transfers per capita" bis14jahre_sh "Share of population < 15 years" ueber65_sh "Share of population > 65 years" businesstax "Business tax rate multiplier" proptax "Property tax B rate multiplier" logpop "Log of population size" pre_any_system "Election/appointment year - 1" pre_bmwahl "Elected mayor*Election/appointment year - 1")  /// ///
  stats(time mayor countytr controls N N_g r2 , layout(@ @ @ @ @ @ )  fmt(%~#s %~#s %~#s %~#s %6.0f %6.0f %6.3f ) ///
 labels("Year fixed effects" "Municipality fixed effects" "County-specific time trends" "Control variables" "Observations" "Municipalities" "R-squared" )) ///
  starlevels(* 0.10 ** 0.05 *** 0.01) ///
 cells(b(star fmt(%8.3f) ) se(par fmt(%6.3f))     ) ///
 postfoot(\bottomrule\end{tabularx}\begin{tablenotes} \scriptsize{\item[] Notes: The dependent variable is the log of investment transfers per capita. Standard errors are robust to heteroscedasticity and clustered at the municipality-level (reported in parentheses). Control variables include share of population over 65 years, share of population below 15 years, log of population size, log of rule-based transfers per capita, and business and property tax rate multipliers. Stars indicate significance levels at 10\% (*), 5\% (**) and 1\%(***).}\end{tablenotes} \end{threeparttable}} \hspace*{\fill}\end{table}) notype


clear 

*********************************************************
*Table 7: Anticipation - first and subsequent elections
*********************************************************
use "$data\final.dta"

*recode to distinguish between first and subsequent mayor elections
gen firstdme = 0
replace firstdme = 1 if wahlperiode ==1 & bmwahl == 1
gen bmwahl2=bmwahl-firstdme

xtivreg2 log_Invzuweis_pc direct_elect bmwahl2 electyr firstdme time*, fe r cluster(code)
est store inv1
estadd local time "YES", replace
estadd local countytr "NO", replace
estadd local mayor "YES", replace
estadd local controls "NO", replace

xtivreg2 log_Invzuweis_pc direct_elect bmwahl2 electyr firstdme time* trend_*, fe r cluster(code)
est store inv2
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "NO", replace

xtivreg2 log_Invzuweis_pc direct_elect bmwahl2 electyr firstdme time* trend_* bis14jahre_sh ueber65_sh log_Schluess_pc logpop businesstax proptax, fe r cluster(code)
est store inv3
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "YES", replace

estout inv1 inv2 inv3 using "$data\table7.tex", ///
rename(appointment councilwahl) ///
style(tex) keep(firstdme direct_elect bmwahl2 electyr) mlabels("(I)" "(II)" "(III)") order(firstdme bmwahl2 direct_elect electyr  ) replace title("Anticipation, first and later direct election: Electoral cycles in investment transfers from the state-tier by electoral rules for mayors") ///
 prehead(\begin{table}[htbp] \scriptsize \hspace{\fill} \resizebox{0.65\textwidth}{!}{\begin{threeparttable}\caption{{\sc @title \label{tab:anticip}}}\centering\medskip ///
 \begin{tabularx}{0.72\textwidth}{P*{@M}{C}} \toprule)  posthead("") prefoot("\midrule") ///
 varlabels(electyr "Election/appointment year" bmwahl "Elected mayor*Election/appointment year" direct_elect "Elected mayor" log_Schluess_pc "Log of rule-based transfers per capita" bis14jahre_sh "Share of population < 15 years" ueber65_sh "Share of population > 65 years" businesstax "Business tax rate multiplier" proptax "Property tax B rate multiplier" logpop "Log of population size" bmwahl2 "Elected mayor*Election/appointment year$ _{n>1}$" firstdme "Elected mayor*Election year$ _{n=1}$")  /// ///
  stats(time mayor countytr controls N N_g r2 , layout(@ @ @ @ @ @ )  fmt(%~#s %~#s %~#s %~#s %6.0f %6.0f %6.3f ) ///
 labels("Year fixed effects" "Municipality fixed effects" "County-specific time trends" "Control variables" "Observations" "Municipalities" "R-squared" )) ///
  starlevels(* 0.10 ** 0.05 *** 0.01) ///
 cells(b(star fmt(%8.3f) ) se(par fmt(%6.3f))     ) ///
  postfoot(\bottomrule\end{tabularx}\begin{tablenotes} \item \scriptsize{Notes: The dependent variable is the log of investment transfers per capita. Standard errors are robust to heteroscedasticity and clustered at the municipality-level (reported in parentheses). Control variables include share of population over 65 years, share of population below 15 years, log of population size, log of rule-based transfers per capita, and business and property tax rate multipliers. Stars indicate significance levels at 10\% (*), 5\% (**) and 1\%(***).}\end{tablenotes} \end{threeparttable}} \hspace*{\fill}\end{table}) notype

 clear 

*****************************
*Table 8: Divided government
*****************************
use "$data\final.dta"

* drop observations where traeger is unclear
drop if mayor_party==""

* create divided government indicator
gen divided=((left_mayor==1&spd_green_majority==0) |(right_mayor==1 & cdu_fdp_majority==0)|(independent_mayor==1&  independent_majority==0)  )
bysort year: egen divided_sum=sum(divided)
bysort year: egen sum_obs=count(code)
gen divided_share=(divided_sum/sum_obs)*100


*Electoral cycle regressions, with divided government subsample
*****************************************************************
preserve
keep if divided==1

xtivreg2 log_Invzuweis_pc direct_elect bmwahl electyr time*, fe r cluster(code)
est store div_inv1
estadd local time "YES", replace
estadd local countytr "NO", replace
estadd local mayor "YES", replace
estadd local controls "NO", replace

xtivreg2 log_Invzuweis_pc direct_elect bmwahl electyr time* trend_*, fe r cluster(code)
est store div_inv2
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "NO", replace

xtivreg2 log_Invzuweis_pc direct_elect bmwahl electyr time* trend_* bis14jahre_sh ueber65_sh log_Schluess_pc logpop businesstax proptax, fe r cluster(code)
est store div_inv3
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "YES", replace
restore

*Electoral cycle regressions, with non-divided government subsample
*****************************************************************
preserve
keep if divided==0

xtivreg2 log_Invzuweis_pc direct_elect bmwahl electyr time*, fe r cluster(code)
est store non_div_inv1
estadd local time "YES", replace
estadd local countytr "NO", replace
estadd local mayor "YES", replace
estadd local controls "NO", replace

xtivreg2 log_Invzuweis_pc direct_elect bmwahl electyr time* trend_*, fe r cluster(code)
est store non_div_inv2
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "NO", replace

xtivreg2 log_Invzuweis_pc direct_elect bmwahl electyr time* trend_* bis14jahre_sh ueber65_sh log_Schluess_pc logpop businesstax proptax, fe r cluster(code)
est store non_div_inv3
estadd local time "YES", replace
estadd local countytr "YES", replace
estadd local mayor "YES", replace
estadd local controls "YES", replace

restore

estout non_div_inv1 non_div_inv2 non_div_inv3 div_inv1 div_inv2 div_inv3 using "$data\table8.tex", ///
rename(appointment councilwahl) ///
style(tex) keep(direct_elect bmwahl electyr ) mlabels("(I)" "(II)" "(III)" "(IV)" "(V)" "(VI)") order(bmwahl direct_elect electyr ) replace title("Electoral cycles in investment transfers from the state-tier by electoral rules for mayors, Non-divided vs. divided government") ///
prehead(\begin{table}[htbp] \scriptsize \hspace{\fill} \resizebox{1\textwidth}{!}{\begin{threeparttable}\caption{{\sc @title \label{tab:divided_government}}}\centering\medskip ///
\begin{tabularx}{1\textwidth}{P*{@M}{C}} \toprule \\ "&\multicolumn{3}{l}{Non-divided government}& \multicolumn{3}{l}{Divided government}\\ \cmidrule(r){2-4}  \cmidrule(r){5-7}"\\) ///
posthead("") prefoot("\midrule") ///
 varlabels(electyr "Election/appointment year" bmwahl "Elected mayor*Election/appointment year" direct_elect "Elected mayor" log_Schluess_pc "Log of rule-based transfers per capita" bis14jahre_sh "Share of population < 15 years" ueber65_sh "Share of population > 65 years" businesstax "Business tax rate multiplier" proptax "Property tax B rate multiplier" logpop "Log of population size")  /// ///
  stats(time mayor countytr controls N N_g r2 , layout(@ @ @ @ @ @ )  fmt(%~#s %~#s %~#s %~#s %6.0f %6.0f %6.3f ) ///
 labels("Year fixed effects" "Municipality fixed effects" "County-specific time trends" "Control variables" "Observations" "Municipalities" "R-squared" )) ///
  starlevels(* 0.10 ** 0.05 *** 0.01) ///
 cells(b(star fmt(%8.3f) ) se(par fmt(%6.3f))     ) ///
 postfoot(\bottomrule\end{tabularx}\begin{tablenotes} \scriptsize{\item[] Notes: The dependent variable is the log of investment transfers per capita. Standard errors are robust to heteroscedasticity and clustered at the municipality-level (reported in parentheses). Control variables include share of population over 65 years, share of population below 15 years, log of population size, log of rule-based transfers per capita, and business and property tax rate multipliers. Stars indicate significance levels at 10\% (*), 5\% (**) and 1\%(***).}\end{tablenotes} \end{threeparttable}} \hspace*{\fill}\end{table}) notype

exit
